package com.android.presenter.info;

import com.android.model.net.HttpObserver;
import com.android.presenter.iview.ISetTradePWDView;
import com.android.model.info.UserModel;
import com.android.presenter.base.BasePresenter;
import com.android.util.log.LogUtil;

import retrofit2.Response;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 设置交易密码前校验
 */

public class SetTradePWDPresenter extends BasePresenter<ISetTradePWDView> {

    private static final String TAG = SetTradePWDPresenter.class.getSimpleName();
    private UserModel mUserModel;

    public SetTradePWDPresenter(ISetTradePWDView iSetTradePWDView) {
        super(iSetTradePWDView);
        mUserModel = UserModel.getInstance();
    }

    public void setTradePassword(String token, String password, String operateType) {
        mUserModel.setTradePassword(token, password, operateType, new HttpObserver<Response<Void>>() {
            @Override
            public void onSuccess(Response<Void> voidResponse) {
                LogUtil.e(TAG, "修改交易密码成功！");
                if (mIView != null) {
                    mIView.setTradePWDSuccess(voidResponse);
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "失败码：" + errType + "》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.setTradePWDFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
